﻿<UserControl x:Class="Bazookabird.Wpf.Queries.QueryHandlers.SimpleSprintViewer.SimpleSprintViewerView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:SimpleSprintViewer="clr-namespace:Bazookabird.Wpf.Queries.QueryHandlers.SimpleSprintViewer"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300"
             x:Name="Control">
    <UserControl.Template>
        <StaticResource ResourceKey="PanelTemplate"/>
    </UserControl.Template>
    <Grid>
        <ListBox ItemsSource="{Binding WorkItemTimelineCollection.WorkItemDateCollection}" 
                 ScrollViewer.HorizontalScrollBarVisibility="Hidden"                 
                 HorizontalContentAlignment="Stretch"
                 ItemContainerStyle="{DynamicResource ItemStyle}">
        	<ListBox.Resources>
                <SimpleSprintViewer:WorkItemScaleConverter x:Key="workItemScaleConverter" />
                <Style x:Key="ItemStyle" TargetType="{x:Type ListBoxItem}">
        			<Setter Property="Background" Value="Transparent"/>
        			<Setter Property="HorizontalContentAlignment" Value="{Binding HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
        			<Setter Property="VerticalContentAlignment" Value="{Binding VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
        			<Setter Property="Padding" Value="2,0,0,0"/>
        			<Setter Property="Template">
        				<Setter.Value>
        					<ControlTemplate TargetType="{x:Type ListBoxItem}">
        						<Border x:Name="Bd" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}" SnapsToDevicePixels="true">
        							<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="Stretch"/>
        						</Border>
        						<ControlTemplate.Triggers>
        							<Trigger Property="IsSelected" Value="true">
        								<Setter Property="Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"/>
        								<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}"/>
        							</Trigger>
        							<MultiTrigger>
        								<MultiTrigger.Conditions>
        									<Condition Property="IsSelected" Value="true"/>
        									<Condition Property="Selector.IsSelectionActive" Value="false"/>
        								</MultiTrigger.Conditions>
        								<Setter Property="Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/>
        								<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
        							</MultiTrigger>
        							<Trigger Property="IsEnabled" Value="false">
        								<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
        							</Trigger>
        						</ControlTemplate.Triggers>
        					</ControlTemplate>
        				</Setter.Value>
        			</Setter>
        		</Style>
        	</ListBox.Resources>
            <ListBox.ItemTemplate>
                <DataTemplate DataType="{x:Type SimpleSprintViewer:WorkItemDate}">
                    <Grid Width="Auto" HorizontalAlignment="Stretch">
                        <Grid.RowDefinitions>
                            <RowDefinition />
                            <RowDefinition Height="30" />
                        </Grid.RowDefinitions>
                        <Rectangle 	HorizontalAlignment="Stretch" 
							VerticalAlignment="Stretch" 
							RenderTransformOrigin="0.5,1">
                        	<Rectangle.RenderTransform>
                        		<TransformGroup>
                                    <ScaleTransform>
                                        <ScaleTransform.ScaleY>
                                            <MultiBinding Converter="{StaticResource workItemScaleConverter}">
                                                <Binding Path="SumHoursRemaining" />
                                                <Binding RelativeSource="{RelativeSource AncestorType=UserControl}" Path="DataContext.MaxScale" />
                                            </MultiBinding>
                                        </ScaleTransform.ScaleY>
                                    </ScaleTransform>
                                    <SkewTransform/>
                        			<RotateTransform/>
                        			<TranslateTransform/>
                        		</TransformGroup>
                        	</Rectangle.RenderTransform>
                            <Rectangle.Fill>
                                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                    <GradientStop Color="#FF8CE552" Offset="0"/>
                                    <GradientStop Color="#FF9F9F9F" Offset="1"/>
                                </LinearGradientBrush>
                            </Rectangle.Fill>
                        </Rectangle>
                        <TextBlock Text="{Binding SumHoursRemaining}" />
                        <Grid Grid.Row="1" Height="30" Background="{x:Null}">
                            <TextBlock 	Text="{Binding Date, StringFormat=d, FallbackValue='Date'}" 
						   		HorizontalAlignment="Center" VerticalAlignment="Center" />
                        </Grid>
                    </Grid>
                </DataTemplate>
            </ListBox.ItemTemplate>
            <ListBox.ItemsPanel>
                <ItemsPanelTemplate>
                    <StackPanel Orientation="Horizontal" VerticalAlignment="Stretch" />
                </ItemsPanelTemplate>
            </ListBox.ItemsPanel>
        </ListBox>        
    </Grid>
</UserControl>
